package com.xiangxiangjd.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.xiangxiangjd.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xiangxiangjd.service.AnswerService;
import com.xiangxiangjd.bean.Answer;
import com.xiangxiangjd.controller.model.ApiResultModel;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 肖守凯
 * @since 2021-05-05
 */
@Controller
@RequestMapping("/star/answer")
public class AnswerController extends BaseController{



     /** 主页面 */
    @RequestMapping("admin/main.html")
    public String main(){
       return  "Answer/AnswerMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "admin/addAnswerHtml")
    public String addAnswerHtml( ){
             return "Answer/AnswerAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/editAnswerHtml")
    public String editAnswerHtml(String id ,Model model ){
           model.addAttribute("answer",answerService.selectAnswerByIdAnswer(id));
             return "Answer/AnswerEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/showAnswerHtml")
    public String showAnswerHtml(String id ,Model model ){
           model.addAttribute("answer",answerService.selectAnswerByIdAnswer(id));
             return "Answer/AnswerShow";
    }


    /** 分页查询Answer
     * @param page  页码
     * @param limit  查几条
     * @param answer  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "admin/findAnswerByPage")
    @ResponseBody
    public ResultPage findAnswerByPage(Integer page, Integer limit,Answer answer){
             return answerService.findAnswerByPage(page,limit,answer);
    }

    /** 添加Answer
     * @param answer  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/addAnswer")
    @ResponseBody
    public ApiResultModel saveAnswer(Answer answer  ){
             return answerService.addAnswer(answer);
    }

    /** 编辑Answer
     * @param answer  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/editAnswer")
    @ResponseBody
    public ApiResultModel editAnswer(Answer answer  ){
             return answerService.editAnswer(answer);
    }



    /** 删除Answer
     * @param ids  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/delAnswer",method = RequestMethod.GET)
    @ResponseBody
    public ApiResultModel delAnswer(@RequestParam("datas[]") ArrayList ids){


             return answerService.delAnswers(ids);
    }


}
